<template>
  <footer>
  	<ul class="nav flexCC">
  		<li class="item1 active" @click.stop="maidian('23015')"></li>
  		<li class="item2 active" @click.stop="toHangqing"></li>
  		<li class="item3 active" @click.stop="check('23017')"></li>
  		<li class="item4 active" @click.stop="toKetang"></li>
      <li class="item5 active" @click.stop="check('23019')"></li>
  	</ul>
  </footer>
</template>

<script>
  import sessionDAO from 'common/sessionDAO'
  import RemoteDAO from 'common/RemoteDAO'
  import Constant from 'common/constant'
  import { getUrlParam } from 'common/common.util'

  export default {
    data () {
      return {
        gameId: ''
      }
    },
    methods: {
      maidian (id) {
        let TDAPP = window.TDAPP
        TDAPP.onEvent(id, '', {userCode: sessionDAO.getUserCode()})
        TDAPP.send()
      },
      toHangqing () {
        let userCode = sessionDAO.getUserCode()
        let gameId = this.$store.state.gameId
        let islogin = 0
        let isAttendGame = 0
        if (userCode) {
          islogin = 1
        }
        if (gameId) {
          isAttendGame = 1
        }
        window.location.href = 'https://i.gtja.com/quotes/quotes/indexGlzb.html?userCode=' + userCode + '&islogin=' + islogin + '&isAttendGame=' + isAttendGame + '&gameId=' + gameId
        this.maidian('23016')
      },
      toKetang () {
        window.location.href = 'gtjayyz://jumpfunc?funid=10019&roomId=1206&fromGLDH=1'
        this.maidian('23018')
      },
      check (id) {
        if (!sessionDAO.getUserCode()) {
          let tgCode = this.$route.query.tgCode || getUrlParam('tgCode')
          RemoteDAO.callNativeLogin(tgCode).then(res => {
            sessionDAO.setUserCode(res.data.user_code)
            window.location.reload()
          }, error => {
            this.$store.dispatch('setTip', {text: error.message})
          })
        } else {
          this.gameId = this.$store.state.gameId
          if (id === '23017') {
            this.toTrade()
          } else if (id === '23019') {
            this.toPosition()
          }
        }
        this.maidian(id)
      },
      toTrade () {
        if (this.gameId) {
          window.location.href = 'gtjayyz://jumpfunc?funid=11007&pagename=trade/buyin&gameId=' + this.gameId
        } else {
          window.location.href = 'gtjayyz://jumpfunc?funid=11007&pagename=team-game/game-detail&gameId=' + Constant.GLDH_ID + '&gameName=股林大会'
        }
      },
      toPosition () {
        if (this.gameId) {
          window.location.href = 'gtjayyz://jumpfunc?funid=11007&pagename=game/gameselfdetail&gameId=' + this.gameId + '&gameName=股林大会&teamName=' + this.$store.state.teamName
        } else {
          window.location.href = 'gtjayyz://jumpfunc?funid=11007&pagename=team-game/game-detail&gameId=' + Constant.GLDH_ID + '&gameName=股林大会'
        }
      }
    }
  }
</script>

